﻿@page "/publish"
@inject IHttpClientFactory Http
@inject IJSRuntime JSRuntime
@inject NavigationManager Navigation
@inject Blazored.LocalStorage.ILocalStorageService localStorage
@inject AuthenticationStateProvider AuthStateProvider
@attribute [Authorize]
@using Microsoft.AspNetCore.Authorization
@using lcwb.Shared.Model
@using System.Security.Claims;
<AntDesign.PageHeader Title="发布内容"></AntDesign.PageHeader>

<AntDesign.Tabs Type="TabType.Card" ActiveKey="@activeKey" OnChange="HandleTabChange">
    @if (isAdmin)
    {
        <AntDesign.TabPane Key="courses" Tab="课程管理">

            <AntDesign.Card Bordered="true" Style="width: 300px; margin: 16px;"
            >
                <AntDesign.Icon Type="plus" />
                <span>课程管理</span>
                <Button Style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;"
                OnClick="() => HandleTabClick()">
                </Button>
            </AntDesign.Card>
        </AntDesign.TabPane>
    }
    <AntDesign.TabPane Key="notes" Tab="笔记管理">
        <AntDesign.Card Bordered="true" Style="width: 300px; margin: 16px;"
        >
            <AntDesign.Icon Type="file-text" />
            <span>笔记管理</span>
            <Button Style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;"
            OnClick="() => HandleTabClick()">
            </Button>
        </AntDesign.Card>
    </AntDesign.TabPane>

    <AntDesign.TabPane Key="articles" Tab="文章管理">
        <AntDesign.Card Bordered="true" Style="width: 300px; margin: 16px;">
            <AntDesign.Icon Type="read" />
            <span>文章管理</span>
            <Button Style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;"
            OnClick="() => HandleTabClick()">
            </Button>
        </AntDesign.Card>
    </AntDesign.TabPane>
</AntDesign.Tabs>


@code {
    private bool isAdmin;
    private string activeKey = "plus";
    private List<Course> courses = new();
    protected override async Task OnInitializedAsync()
    {
        var authState = await AuthStateProvider.GetAuthenticationStateAsync();
        var user = authState.User;
        isAdmin = user.IsInRole("Admin");
    }

    private void HandleTabChange(string key)
    {
        activeKey = key;
        StateHasChanged();
    }
    private void HandleTabClick()
    {
        if (activeKey == "courses")
        {
            Navigation.NavigateTo("/publish/course");
        }
        else if (activeKey == "notes")
        {

        }
        else if (activeKey == "articles")
        {

        }
        else
        {
            
        }
    }
}